# Definition for a Node.
class Node:
    def __init__(self, x: int, next: 'Node' = None, random: 'Node' = None):
        self.val = int(x)
        self.next = next
        self.random = random


class Solution:
    def copyRandomList(self, head: 'Node') -> 'Node':
        if not head:
            return None
        p = Node(head.val)
        p1, p2 = p, head
        while p2.next:
            p1.next = Node(p2.next.val)
            p2 = p2.next

        return p